import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDSettingsHead {
	/**ID*/
	id,
	/**类型：0初始默认--1.宠物，校验该宠物是否拥有过--2.皮肤，校验该皮肤是否拥有*/
	type,
	/**校验id*/
	param,
	/**头像框*/
	head,

	/**枚举数量*/
	EnumCount
}



export class CDSettingsHead{
	/**ID*/
	public id: number;
	/**类型：0初始默认--1.宠物，校验该宠物是否拥有过--2.皮肤，校验该皮肤是否拥有*/
	public type: number;
	/**校验id*/
	public param: number;
	/**头像框*/
	public head: string;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDSettingsHead.id: return this.id;
			case E_CDSettingsHead.type: return this.type;
			case E_CDSettingsHead.param: return this.param;
			case E_CDSettingsHead.head: return this.head;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDSettingsHead.id: this.id = v; break;
			case E_CDSettingsHead.type: this.type = v; break;
			case E_CDSettingsHead.param: this.param = v; break;
			case E_CDSettingsHead.head: this.head = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDSettingsHead> = new HashMap<number, CDSettingsHead>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDSettingsHead[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDSettingsHead();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].type = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].param = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].head = byte.readString();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDSettingsHead{
		return this.datas ? this.datas.get(id) : null;
	}
}
